﻿using UnityEngine;
using System.Collections;

public class DayNightCycle : MonoBehaviour
{
    [SerializeField]
    private GameObject Moon;
    [SerializeField]
    private float speed;

    private float timer_sun;
    bool isDay;

    void Start()
    {
        timer_sun = 0;
        isDay = true;
        //gameObject.GetComponent<Light>().intensity = isDay ? 0.5f : 0.0f;
        //Moon.GetComponent<Light>().intensity = isDay ? 0.0f : 0.5f;
    }

    void Update()
    {
        transform.RotateAround(Vector3.zero, Vector3.right, speed * Time.deltaTime);

        //gameObject.GetComponent<Light>().intensity = isDay ? Mathf.Lerp(0.5f, 0, Mathf.Abs(((90f / speed) - timer_sun) / (90f / speed))) : Mathf.Lerp(0.0f, 0.5f, Mathf.Abs(((90f / speed) - timer_sun) / (90f / speed)));
        //Moon.GetComponent<Light>().intensity = isDay ? Mathf.Lerp(0.0f, 0.5f, Mathf.Abs(((90f / speed) - timer_sun) / (90f / speed))) : Mathf.Lerp(0.5f, 0.0f,Mathf.Abs(((90f / speed) - timer_sun) / (90f / speed)));


        if (timer_sun >= 180f / speed)
        {
            isDay = !isDay;
            timer_sun -= 180f / speed;


        }
        else
            timer_sun += Time.deltaTime;
    }
}
